<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑主题--管理后台</title>
    <link th:href="@{/css/admin.css}" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="main">
    <div th:replace="admin/common :: #top"></div>
    <div th:replace="admin/common :: #opt_list"></div>
    <div id="opt_area">
        <span th:if="${error!=NULL}" th:text="${error}" style="color: red"></span>
        <ul class="classlist">

            <li th:each="topic:${topics}">
                <label th:text="${topic.tname}" style="position: relative">国内</label>
                &nbsp;&nbsp;&nbsp;&nbsp;<span> <a th:href="@{/topic/toupdate(tid=${topic.tid})}">修改</a>&#160;&#160;&#160;&#160;
                &nbsp;&nbsp;&nbsp;&nbsp;
                <!--                <a href="@{/topic/delete(tid=${topic.tid})}">删除</a>-->
                <a href="javascript:;" th:id="${topic.tid}" onclick="del(this)">删除</a>
            </span>
            </li>

        </ul>
    </div>
    <div th:replace="admin/common :: #footerbar"></div>
</div>

<script th:src="@{/js/jquery-1.8.3.min.js}"></script>
<script type="text/javascript">
    function del(obj) {
        // alert(obj.getAttribute("id"));
        var tid = obj.getAttribute("id");
        if (confirm("确定要删除吗？")) {
            $.ajax(
                {
                    url: "/topic/newsexists?tid=" + tid,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        if (data.result == "true") {
                            alert("该主题下有新闻，不能删除");
                        } else {
                            location.href = "/topic/delete/?tid=" + obj.getAttribute("id")
                        }
                    }
                }
            )


        }
    }
</script>
</body>
</html>	